<template>
	<view class="index-page page">
		<scroll-view :scroll-y="true" class="content">
			<CustomNav :normal="{ textColor: '#fff', background: '#FF2F34' }" title="我的推广" :is-back="true"></CustomNav>
			<view class="top-block">
				<view class="search-block">
					<view class="input-block">
						<view class="input-left">
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/search.png"
								mode=""></image>
							<input placeholder="请输入关键字" v-model="keyword" @confirm="search" />
						</view>
						<view class="search" @click="search">
							搜索
						</view>
					</view>
				</view>
			</view>
			<view class="info-block">
				<view class="gift" style="margin-right: 20rpx;">
					<view class="gift-top">
						<view class="top-left">总收益积分</view>
					</view>
					<view class="gift-bottom">
						<view class="">
							{{sumIncomeIntegral}}<text style="font-size: 32rpx;">分</text>
						</view>
						<view class="fans">粉丝数：{{fans}}个</view>
					</view>
				</view>
			</view>
			<template v-if="list.length>0">
				<view class="user-block" v-for="item in list" :key="item.id">
					<view class="user-top">
						<view class="user-item">
							<image :src="cloudStorage+item.faceUrl" mode=""></image>
							<view class="username">
								<view class="user-title">{{item.userName}}</view>
								<view class="phone">{{item.phone}}</view>
							</view>
						</view>
						<view class="accounts" v-if="item.vip===1"
							@click="navigate('/page_other/accounts/accounts?code=' + item.invitationCode)">转账</view>
					</view>
					<view class="user-middle">
						<view class="user-item">
							<view class="money">￥{{item.todayConsume}}</view>
							<view class="user-title">今日消费</view>
						</view>
						<view class="user-item">
							<view class="money">￥{{item.sumConsume}}</view>
							<view class="user-title">累计消费</view>
						</view>
						<view class="user-item">
							<view class="money">￥{{item.todayIncome}}</view>
							<view class="user-title">今日收益</view>
						</view>
						<!-- <view class="user-item">
							<view class="money">￥{{item.contributeIntegral}}</view>
							<view class="user-title">贡献积分</view>
						</view> -->
					</view>
					<view class="user-time">
						<view class="register">注册时间：</view>
						<view class="time">{{item.createTime}}</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" style="width:100%;text-align: center;">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" style="width:100%;text-align: center;">没有更多了</view>
		</scroll-view>
	</view>
</template>

<script>
	import CustomNav from '@/components/CustomNav/CustomNav';
	import {
		getUserInviteRecord
	} from '@/api/mine.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				keyword: '',
				sumIncomeIntegral: '',
				fans: null,
				conf: {
					page: 1,
					limit: 10,
				},
				more: true,
				list: [],
			};
		},
		methods: {
			search() {
				this.getList(true)
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			//用户查我的推广
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getUserInviteRecord({
					page: this.conf.page,
					limit: this.conf.limit,
					keyword: this.keyword,
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
					this.fans = res.fansCount
					this.sumIncomeIntegral = res.sumIncomeIntegral
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad() {
			this.getList(true)
		}
	};
</script>

<style scoped lang="scss">
	.index-page {
		overflow: hidden;

		.top-banner {
			width: 100%;
		}

		.content {
			width: 100%;
			overflow-y: auto;
			position: relative;

			.top-block {
				width: 100%;
				height: 220rpx;
				margin-top: 160rpx;
				background-color: #FF2F34;
				padding: 30rpx;
			}

			.search-block {
				width: 100%;
				height: 70rpx;
				display: flex;


				.address-block {
					display: flex;
					background-color: #FFFFFF;
					align-items: center;
					justify-content: center;
					width: 130rpx;
					border-radius: 50px;
					margin-right: 20rpx;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-right: 5rpx;
					}

					.address {
						color: #FF2F34;
						font-size: 28rpx;
					}
				}

				.input-block {
					display: flex;
					background-color: #FFFFFF;
					border-radius: 50px;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					padding: 6rpx 6rpx 6rpx 20rpx;

					.input-left {
						width: calc(100% - 140rpx);
						display: flex;

						image {
							width: 30rpx;
							height: 30rpx;
							// margin-right: 5rpx;
							margin: 7rpx 7rpx 0 0;
						}

						input {
							border-radius: 50px;
							width: 100%;

						}
					}

					.search {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 130rpx;
						border-radius: 50rpx;
						height: 100%;
						padding-bottom: 5rpx;
						color: #FFFFFF;
						background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
					}
				}
			}

			.info-block {
				position: relative;
				background-color: #f7f6f9;
				border-radius: 50rpx 50rpx 0 0;
				padding: 30rpx;
				margin-top: -60rpx;

				.gift {
					width: 100%;
					height: 300rpx;
					background-image: url('https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/mine.png');
					background-size: 100%;
					padding: 40rpx 40rpx;
					border-radius: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;

					.gift-top {
						display: flex;
						justify-content: space-between;

						.top-left {
							color: #FFFFFF;
							font-size: 32rpx;
						}

						.top-right {
							width: 30rpx;
							height: 30rpx;
						}

					}

					.gift-bottom {
						margin-top: 20rpx;
						font-size: 64rpx;
						color: #FFFFFF;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.fans {
							color: #FFFFFF;
							font-size: 32rpx;
						}
					}
				}

			}

			.user-block {
				width: calc(100% - 60rpx);
				padding: 40rpx 30rpx 30rpx;
				border-radius: 20rpx;
				background-color: #FFFFFF;
				margin: 0 auto 30rpx;

				.user-top {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 30rpx;

					.user-item {
						display: flex;
						align-items: center;

					}

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50rpx;
						margin-right: 20rpx;
					}

					.username {
						display: flex;
						flex-direction: column;
						justify-content: space-around;

						.user-title {
							margin-bottom: 10rpx;
						}

						.phone {
							font-size: 12px;
							font-weight: normal;
							line-height: normal;
							letter-spacing: 0em;
							color: #767676;
						}
					}

					.accounts {
						background-color: #FF2F34;
						color: #fff;
						font-size: 30rpx;
						padding: 6rpx 16rpx;
						border-radius: 10rpx;
					}
				}

				.user-middle {
					display: flex;
					justify-content: space-between;
					margin-bottom: 30rpx;

					.user-item {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;

						.money {
							margin-bottom: 10rpx;
						}

						.user-title {
							color: #767676;
							font-size: 14px;
							font-weight: normal;
							line-height: 22px;
							text-align: center;
							letter-spacing: 0px;
						}
					}
				}

				.user-time {
					display: flex;
					font-size: 12px;
					font-weight: normal;
					line-height: normal;
					letter-spacing: 0em;
					color: #767676;
				}

			}



		}
	}
</style>